<?php
include_once './inc/config_inc.php';
include_once './inc/mysql_inc.php';
include_once './inc/tool_inc.php';
$link=connect();
$user_id=is_login($link);
if($user_id){
	skip('index.php','error','你已经登录，请不要重复注册！');exit();
}

if(isset($_POST['submit'])){
	include 'inc/check_register_inc.php';
	$query="insert into user(name,pw,photo,create_time) values('{$_POST['name']}',md5('{$_POST['pw']}'),'',now())";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		setcookie('blog[name]',$_POST['name']);
		setcookie('blog[pw]',sha1(md5($_POST['pw'])));
		skip('index.php','ok','注册成功！'); exit();
	}else{
		skip('register.php','eror','注册失败,请重试！');exit();
	}
}

$template['title']='注册';
$template['css']=array('style/public.css','style/register.css');
?>
<?php include 'inc/header_inc.php';?>

<!--注册-->
<div id="register" class="auto">
	<h2>欢迎用户注册</h2>
	<form method="post" action=" " onsubmit="return check()">
		<label>用户名：<input type="text" id="name" name="name"/><span>*用户名不得为空，且不得多于10位</span></label>
		<label>密码：<input type="password" id="pw" name="pw" /><span>*密码不得为空，且在6~10位之间</span></label>
		<label>确认密码：<input type="password" id="confirm_pw" name="confirm_pw" /><span>*确认密码</span></label>
		<label>验证码：<input name="vcode" type="text" id="vcode"/><span>*请输入下方验证码</span></label>
		<img class="vcode" src="show_code.php" />
		<div style="clear:both;"></div>
		<input class="btn" type="submit" id="submit" name="submit" value="确定注册" />
	</form>
</div>
<script type="text/javascript">
	function check(){
		var username=document.getElementById('name').value;
		var password=document.getElementById('pw').value;
		var confirm_password=document.getElementById('confirm_pw').value;
		var yanzhengma=document.getElementById('vcode').value;

		if(username===""){
			alert("请输入用户名!");
			return false;
		}else{
			if(username.length>10){
				alert("用户名不得多于10位");
				return false;
			}
		}
		if(password===""){
			alert("请输入密码!");
			return false;
		}
		if(confirm_password===""){
			alert("请再次输入密码!");
			return false;
		}else{
			if(confirm_password!=password){
				alert("两次密码输入不一致!");
				return false;
			}
		}
		if(yanzhengma===""){
			alert("请输入验证码!");
			return false;
		}
	}
</script>
<?php include 'inc/footer_inc.php'?>